﻿using AutoMapper;
using ManagementApi.Models.System.Dept;
using Modules.System.Dept;
using Modules.System.Role;
using PmSoft;
using static Modules.Project.ProjectConstants;

namespace ManagementApi.Models.System.Role
{
    /// <summary>
    /// 角色视图对象
    /// </summary>
    public class RoleDto
    {
        /// <summary>
        /// 角色Id 
        ///</summary>
        public int RoleId { get; set; }

        /// <summary>
        /// 角色名称 
        ///</summary>
        public string Name { get; set; } = string.Empty;

        /// <summary>
        /// 角色编码 
        ///</summary>
        public string Code { get; set; } = string.Empty;

        /// <summary>
        /// 显示顺序 
        ///</summary>
        public int? Sort { get; set; }

        /// <summary>
        /// 角色状态(1-正常；0-停用) 
        ///</summary>
        public RoleStatus Status { get; set; }

        /// <summary>
        /// 逻辑删除标识(0-未删除；1-已删除) 
        ///</summary>

        public byte? Deleted { get; set; }
        /// <summary>
        /// 更新时间 
        ///</summary>

        public DateTime? CreateTime { get; set; }

        /// <summary>
        /// 创建时间 
        ///</summary>
        public DateTime? UpdateTime { get; set; }

        public 行业主管部门 IndustryType { get; set; }
        /// <summary>
        /// 行业分类
        /// </summary>
        public string IndustryTypeName {  get; set; }
    }

    public static partial class SysRoleExceptions
    {
        public static RoleDto AsRoleDto(this SysRole role)
        {
            var mapper = ServiceAccessor.GetService<IMapper>();
            RoleDto dto = new RoleDto();
            mapper.Map(role, dto);
            dto.IndustryTypeName = role.IndustryType?.GetDescription()??"";
            return dto;

        }
    }
}
